<template>
  <div>
    <form @submit.prevent="fn" @keyup.enter.prevent="">
      <label>姓名：</label>
      <input type="text" v-model.trim="obj.uname"><br><br>

      <label>年龄：</label>
      <input type="number" v-model.trim="obj.age"><br><br>

      <label>身高：</label>
      <input type="text" v-model.number.trim="obj.heigh">(米)<br><br>

      <label>体重：</label>
      <input type="number" v-model="obj.weight">(公斤)<br><br>

      <label>病史：</label>
      <input type="text" v-model.trim="obj.history"><br><br>

      <button>诊断</button>
    </form>

    <p v-if="flag">患者 {{obj.uname}} 的诊断结果：{{obj.result}}</p>
  </div>
</template>

<script>
export default {
  data () {
    return {
      flag:false,
      obj:{
        uname:'',
        age:'',
        heigh:'',
        weight:'',
        history:'',
        result:'',
      }

    }
  },
  methods: {
    fn(){
      this.flag = true
      console.log(this.obj);
      const sum = (this.obj.weight/(this.obj.heigh*this.obj.heigh))
      if(sum >=18.5 && sum <=24.9){
        this.obj.result = "正常"
      }else if(sum>24.9){
        this.obj.result = "体重过重了"
      }else{
        this.obj.result = "体重过轻了"
      }
    
      
    }

  }
}
</script>